# 2.生日悖论分析
import random

def has_same_birthday(n):
    # 生成n个人的生日，每个人的生日在1到365之间
    birthdays = [random.randint(1, 365) for _ in range(n)]
    # 判断是否有相同生日
    if len(birthdays) != len(set(birthdays)):
        return True
    else:
        return False

def calculate_probability(num_samples, num_people):
    count = 0
    for _ in range(num_samples):
        if has_same_birthday(num_people):
            count += 1
    probability = count / num_samples
    return probability

num_people = 23
num_samples = 10000
probability = calculate_probability(num_samples, num_people)
print(f"在{num_samples}个随机样本中，{num_people}个人中至少有两个人生日相同的概率为: {probability:.2f}")
